<template>
	<div class="agent">
		<div>
			<label>{{$t('route.Device')}}</label>
			<div></div>
			<button><img /><label>{{$t('route.agent')}}</label></button>
		</div>


		<div>
			<div>
				<div class="div-handle-right">
					<el-button @click='jumpPage(0)'>{{$t('route.Add')}}</el-button>
					<el-button @click="searchClick">{{$t('route.search')}}</el-button>
					<input v-model="query.search" placeholder="" />
				</div>
			</div>

			<el-table class="table" :data="agentList" style="width: 100%">
				<el-table-column type="selection" width="55" />
				<el-table-column prop="number" :label="$t('route.ID')" />
				<el-table-column prop="name" :label="$t('route.designation')" />
				<el-table-column prop="address" :label="$t('route.address')" />
				<el-table-column prop="region" :label="$t('route.Area')" />
				<el-table-column prop="contactName" :label="$t('route.Contact_Name')" />
				<el-table-column prop="contactMobile" :label="$t('route.Telephone')" />
				<el-table-column :label="$t('route.Add_date')">
					<template #default="scope">
						{{new Date(scope.row.gmtCreate).format('yyyy-MM-dd')}}
					</template>
				</el-table-column>
				<el-table-column :label="$t('route.operate')" width="240">
					<template #default="scope">
						<el-button type="text" @click="editClick(scope.row)">{{$t('route.Editing')}}</el-button>
						<el-button type="text" @click="batchSNClick(scope.row)">{{$t('route.Batch_SN')}}</el-button>
						<el-button type="text" style="color:red" @click="deleteClick(scope.row)">
							{{$t('route.Delete')}}</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination style="float: right;" background @current-change="handlePageChange"
					:current-page="query.pageNum" :page-size="query.pageSize" layout="total, prev, pager, next"
					:total="query.total"></el-pagination>
			</div>

		</div>

		<!-- 编辑弹出框 -->
		<el-dialog :title="$t('route.oBatch_generated_sequence_numberperate')" v-model="dialogVisible">
			<el-form label-position="right" label-width="120px">
				<el-form-item :label="$t('route.amount')">
					<el-input-number v-model="serialNumCount" :min="1" :max="10000" />
				</el-form-item>
				<el-form-item>
					<el-button @click='addClick'>{{$t('route.Add')}}</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>

	</div>
</template>

<script>
	import http from "../../js/http/http.js";
	import api from "../../js/http/api.js";
	import CommonUtils from "../../js/common/common-utils.js";
	import * as echarts from 'echarts';
	import i18n from '../../i18n/index';
	export default {
		data() {
			return {
				query: {
					pageNum: 1,
					pageSize: 10,
					total: 0,
					search: null,
				},
				agentList: [],
				selAgent: null,
				dialogVisible: false,
				serialNumCount: 1
			};
		},
		methods: {
			batchSNClick(item) {
				this.selAgent = item;
				this.dialogVisible = true;
			},
			addClick() {
				http.post(api.CREATE_SN_BATCH, {
					count: this.serialNumCount,
					adminId: this.selAgent.id
				}, data => {
					this.$message.success(i18n.global.t('route.Build_succeeded'));
					this.dialogVisible = false;
					this.$router.push("/admin/serial-num");
				});
			},
			handlePageChange(pageNum) {
				this.query.pageNum = pageNum;
				this.getAgentList();
			},
			jumpPage(type) {
				if (type == 0) {
					this.$router.push("/admin/add-agent");
				}
			},
			searchClick() {
				this.query.pageNum = 1;
				this.getAgentList();
			},
			getAgentList() {
				http.post(
					api.GET_AGENT_LIST, {
						pageNum: this.query.pageNum,
						pageSize: this.query.pageSize,
						search: this.query.search
					},
					data => {
						this.agentList = data.data.agentList;
						this.total = data.data.total;
					}
				);
			},
			deleteClick(agent) {
				this.$confirm(i18n.global.t('route.Are_you_sure_you_want_to_delete_this_agent'), i18n.global.t('route.reminder'), {
					confirmButtonText: i18n.global.t('route.sure'),
					cancelButtonText: i18n.global.t('route.cancel'),
					type: "warning"
				}).then(() => {
					this.deleteAgent(agent.id)
				});
			},
			deleteAgent(agentId) {
				http.post(
					api.DELETE_AGENT, {
						agentId: agentId,
					},
					data => {
						this.$message.success(i18n.global.t('route.Delete_succeeded'));
						this.getAgentList();
					}
				);
			},
		},
		created() {
			this.getAgentList();
		},
	};
</script>
<style lang="scss" scoped>
	.agent {
		color: #444444;
		font-size: 18px;
		padding-right: 20px;
		height: calc(100vh - 100px);
		// overflow: scroll;
		scrollbar-width: none;
		/* firefox */
		-ms-overflow-style: none;
		/* IE 10+ */
		overflow-x: hidden;
		overflow-y: auto;

		>div:nth-of-type(1) {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;

			>label:nth-of-type(1) {
				font-weight: 600;
			}

			>div:nth-of-type(1) {
				width: 1px;
				background-color: #cccccc;
				height: 15px;
				margin: 0px 20px;
			}

			>button:nth-of-type(1) {
				background-image: url(../../assets/img/customer-1.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				padding: 5px 10px;
				border: 0px;
				display: flex;
				color: #ffffff;
				flex-direction: row;
				align-items: center;
				font-weight: 800;

				>img {
					margin-right: 7px;
					width: 15px;
					height: 15px;
					content: url(../../assets/img/customer-2.png);
				}
			}
		}

		>div:nth-of-type(2) {
			display: flex;
			flex-direction: column;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;


			>div:nth-of-type(1) {
				display: flex;
				flex-direction: row;
				align-items: center;

				.div-handle-right {
					flex: 1;
					flex-direction: row-reverse;
					text-align: right;
					display: flex;
					align-items: center;

					>input:nth-of-type(1) {
						border: 1px solid #eeeeee;
						font-size: 15px;
						width: 200px;
						padding: 5px 8px;
						outline: none;
					}

					>button {
						color: #A866FF;
						margin-left: 10px;
						padding: 4px 20px;
					}
				}
			}

			.table {
				margin-top: 20px;
			}

		}

		.select {
			width: 120px;
			margin-top: 10px;
		}

		.echart {
			height: 150px;
			width: 100%;
		}

		.input {
			width: 250px;
		}


	}
</style>
